package nl.weeaboo.sh.objects;

import java.awt.Rectangle;

import nl.weeaboo.game.gl.GLImage;
import nl.weeaboo.game.gl.GLManager;
import nl.weeaboo.game.input.UserInput;
import nl.weeaboo.sh.Game;
import nl.weeaboo.sh.level.Level;
import nl.weeaboo.sh.model.DamageRect;

public class Platform extends Sprite {

	private GLImage image;
	private Rectangle hitRects[];
	private float speedX, speedY;

	public Platform(Game game, Level level, GLImage image) {
		super(game, level);

		this.image = image;
				
		hitRects    = new Rectangle[1];
		hitRects[0] = new Rectangle(0, 0, 0, 0);
				
		setSpeed(3, -1);
	}
	
	//Functions
	public void update(UserInput input, float dt) {
		super.update(input, dt);
		
		x += Math.round(speedX);
		y += Math.round(speedY);

		setHitBox(image.getWidth()/2, image.getHeight()/2);
	}
	
	protected void drawImage(GLManager glm) {
		image.draw(glm, -image.getWidth()/2, -image.getHeight()/2,
				image.getWidth(), image.getHeight());		
	}

	//Getters
	public float getSpeedX() { return speedX; }
	public float getSpeedY() { return speedY; }
	public Rectangle[]  getHitRects() {    return hitRects; }
	public DamageRect[] getDamageRects() { return Sprite.noDamageRects; }
	public DamageRect[] getSplashRects() { return Sprite.noDamageRects; }
	
	//Setters
	public void setSpeed(float sx, float sy) {
		speedX = sx;
		speedY = sy;
	}
	protected void setHitBox(int rx, int ry) {
		Rectangle rect = hitRects[0];
		rect.x = -rx;
		rect.y = -ry;
		rect.width = 2*rx;
		rect.height = 2*ry;
	}
	
}
